<?php

namespace app\admin\controller;

use my\Security;
use my\Tools;
use think\Cache;
use think\Db;
use think\Env;
class Index extends Base
{

	public function ceshi(){
		$res = Tools::aliUpload('app_ad/mima_ad.png','/mnt/hgfs/share/mima_ad.png');
		echo "<pre>";
		print_r($res);
		echo "</pre>";
	}
	//后台界面
	public function index()
	{
		include_once('socket_param.php');
		$encode = urlencode(Security::encrypt(json_encode(array('admin_id' => session('admin_id'), 'admin_name' => session('admin_name')))));
		$this->assign('ws', $socket['ws'] . "/?encode=" . $encode);
		$this->assign('protocol', PROTOCOL);
		$this->assign('url', ENV=='Pro'?Env::get('url'.ENV.'_url'):Env::get('url'.ENV.'_url').':'.$socket['port']);
		$this->assign('admin_id', session('admin_id') );
		$this->assign('link', $socket['link']);//控制是否进行长连接
		$this->assign('car_net', Env::get('coordinate'.ENV.'_index'));//控制是否进行长连接
		return $this->fetch();
	}

	//后台首页
	public function main()
	{
		$version_list = Db::name('version')->where('type', 1)->select();

		$v = Db::query("select VERSION() as version");
		$map_user = array();
        $map_driver=$map_order_inner=$this->mapData;
		$map_driver['auth_status'] = 1;
		$map_order_inner['order_status'] = array('not in',array(10,15));
		$map_order_inter['order_status'] = array('gt',25);
		if($this->base_condition){
			switch($this->base_condition['admin_type']){
				case 2:
					$map_user['register_province'] = $map_driver['work_province'] = $this->base_condition['region_area'];
					break;
				case 3:
					$map_user['register_city'] = $map_driver['work_city'] = $this->base_condition['region_area'];
					break;
				case 4:
					$map_user['register_county'] = $map_driver['work_county'] = $this->base_condition['region_area'];
					break;
			}
			$map_order_inter['start_code'] = $map_order_inner['start_code'] = $this->base_condition['region_code'];
		}
		//***用户总数
		$user_mount = Db::name('user')->where($map_user)->count();
		//***城际司机总数
		$inter_driver = Db::table('xm_driver a')
            ->where($map_driver)->count();
		//***城内司机总数
		$inner_driver = Db::table('xm_driver a')
            ->where($map_driver)->count();
		//***城内订单总数
		$inner_order = Db::table('xm_order_common a')->where($map_order_inner)->count();
		//***城际订单数
		$inter_order = Db::table('xm_order_common a')->where($map_order_inter)->count();
		//****版本更新
		$version_info = Db::table('xm_system_version')->order('id asc')->select();
		foreach ($version_info as $key => $value) {
			$version_info[$key]['time'] = date('Y-m-d H:i:s',$value['time']);
		}
		$this->assign('version_info', $version_info);
		$this->assign('user_mount', $user_mount);
		$this->assign('inter_driver', $inter_driver);
		$this->assign('inner_driver', $inner_driver);
		$this->assign('inner_order', $inner_order);
		$this->assign('inter_order', $inter_order);
		$this->assign('server', $_SERVER);
		$this->assign('version_list', $version_list);
		$this->assign('version', $v[0]['version']);
		$this->assign('protocol', PROTOCOL);
		//echo "<pre>";
		//print_r($menu_list);
		//echo "</pre>";
		return $this->fetch();
	}

}
